<%--
  ~ Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  ~ Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
  ~ Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
  ~ Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
  ~ Vestibulum commodo. Ut rhoncus gravida arcu.
  --%>

<%--
  Created by IntelliJ IDEA.
  User: dengdc
  Date: 2017/7/19
  Time: 17:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>编辑</title>
    <jsp:include page="../../head.jsp"/>
    <script type="text/javascript">
        function formatDate(date) {
            var datetime = date.getFullYear()
                           + "-"// "年"
                           + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
                           + (date.getMonth() + 1))
                           + "-"// "月"
                           + (date.getDate() < 10 ? "0" + date.getDate() : date
                    .getDate());
            return datetime;
        }
        var today = formatDate(new Date());
        var formSetting = {
            title: "编辑协议",
            module: 'save',
            columns: [
                {
                    name: "id",
                    hidden: true
                }, {
                    name: "name",
                    label: "名称",
                    validate: 'validate[required]'
                }, {
                    name: "supplierId",
                    label: "业务供应商",
                    type: "dropdown",
                    dropdownType: "ajax",
                    url: "<s:url value='/order-dropdown/supCompanyByKey'/>",
                    op: "eq",
                    minLength: 0,
                    keyWordName: "key",
                    success: function (data) {
                        data = data.results;
                        var array = new Array();
                        $.each(data, function (i, n) {
                            array.push([n["name"], n["value"]]);
                        });
                        $("#saveButton").attr("disabled", false);
                        return array;
                    },
                    validate: 'validate[required]'
                }, {type: "spaceHolder"}, {
                    name: "eftimeStart",
                    label: "生效时间",
                    type: 'date',
                    value: today,
                    validate: 'validate[required]'
                }, {
                    name: "eftimeEnd",
                    label: "失效时间",
                    type: 'date',
                    value: today,
                    validate: 'validate[required]'
                }, {
                    name: "remark",
                    label: "备注",
                    type: 'textarea',
                    colspan: 3
                }, {
                    name: "file",
                    realName: "attachment",
                    label: "附件",
                    type: 'file',
//                    readonly: true,
                    href: 'file.id',
                    colspan: 2,
                    validate: 'validate[required,funcCall[checkFile]]'
                }],
            form: {
                'url': 'saveOrUpdate',
                'data': function () {
                    var dataValue = "";
                    $.ajax({
                               url: "editData?id=${param.id}&feeIeType=${param.feeIeType}",
                               async: false,
                               success: function (data) {
                                   dataValue = data;

                               }
                           });
                    return dataValue;
                },
                'ajaxForm': {
                    success: function (result) {
                        parent.layer.msg(result.msg);
                        if (result.result) {
                            parent.window.location.href =
                                '<s:url value="/fund/protocol/manage/unite/editView?id="/>'
                                + result.data;
                        } else {
                            $("#saveButton").attr("disabled", false);
                        }
                    }
                }
            },
            buttons: {
                custom: []
            }
        };
        $(document).ready(function () {
            $("#table").mrdForm(formSetting);
            $("#saveButton").click(function () {
                $("#saveButton").attr("disabled", "disabled");
            });
            $("input[name='attachment']").change(function () {
                $("#" + $.mrdForm.formId).validationEngine("validate");
                $("#saveButton").attr("disabled", false);
            });
            $("input[name='name']").change(function () {
                $("#saveButton").attr("disabled", false);
            });
            $("input[name='name']").keypress(function () {
                if (event.keyCode == "13" || event.keyCode == "32") {//按回车或空格
                    $("input[name='control_supplierId_dropdown']").click();
                }
            });
            $.validationEngine.defaults.validationEventTrigger = "change";
        });

        function checkFile() {
            var fileInput = $("input:file");
            if (fileInput.val() !== "" && fileInput.val().trim().length > 0) {
                if (fileInput[0].files[0].size > 30 * 1024 * 1024) {
                    return "文件应不大于30M";
                }
            }
        }
    </script>
    <style type="text/css">
        .ui-autocomplete {
            max-height: 198px;
            overflow-y: auto;
        }
    </style>
</head>
<body>
<div id="table"></div>
</body>
</html>
